if condition ! falsy value


Posted by mijouhsieh on 2023-03-27

// 錯誤寫法
if(!movies || !(movies.length === 0 )) { return }

正確寫法
if(!movies || !movies.length) return

movies.length若為0 就是 false
!false 就是 true
所以不用寫(movies.length === 0)

return 在同一行,不用寫{}


#|| #OR operator #! #debug







Related Posts

《鳥哥 Linux 私房菜:基礎篇》Chapter 01 - Linux 是什麼與如何學習

《鳥哥 Linux 私房菜:基礎篇》Chapter 01 - Linux 是什麼與如何學習

DAY5:Delete occurrences of an element if it occurs more than n times

DAY5:Delete occurrences of an element if it occurs more than n times

生命週期

生命週期


Comments